package cn.jingzhuan.fm

import android.app.Activity
import android.app.Application
import cn.jingzhuan.fm.di.injection.ApplicationComponent
import cn.jingzhuan.fm.di.injection.DaggerApplicationComponent
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import javax.inject.Inject

class App: Application(), HasActivityInjector {
    @Inject
    lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>

    override fun activityInjector(): AndroidInjector<Activity>  = dispatchingAndroidInjector

    lateinit var applicationComponent: ApplicationComponent


    override fun onCreate() {
        super.onCreate()
        applicationComponent = DaggerApplicationComponent.builder().build()
        applicationComponent.inject(this)
        instance = this
    }

    companion object {
        internal var instance: App? = null

        fun getInstance(): App? {
            return instance
        }
    }

}